package com.jyw.business.de.domain.dto.web;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.jyw.business.de.domain.DeDemandResearch;
import com.jyw.common.annotation.Excel;
import com.jyw.common.utils.DateUtils;
import com.jyw.common.utils.SecurityUtils;
import com.jyw.common.utils.bean.BeanUtils;
import com.jyw.system.domain.vo.SimpleFileVo;
import com.jyw.system.utils.FileUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.util.CollectionUtils;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

@Data
@ApiModel("需求调研请求")
public class DemandResearchAddDto {

    /** 需求id */
    @ApiModelProperty("需求id")
    @NotNull(message = "需求id不能为空")
    private Long demandId;

    /** 调研成员(集合) */
    @ApiModelProperty("调研成员(多选逗号拼接)")
    @NotNull(message = "调研成员不能为空")
    private List<Long> researchUser;

    /** 涉及系统(数据字典多选) */
    @ApiModelProperty("涉及系统(数据字典多选)")
    private List<String> researchSystem;

    /** 调研内容 */
    @ApiModelProperty("调研内容")
    @NotEmpty(message = "调研内容及说明不能为空")
    private String researchRemark;

    /** 调研附件 */
    @ApiModelProperty("调研附件")
    private List<SimpleFileVo> researchEnclosure;

    /** 调研时间 */
    @ApiModelProperty("调研时间")
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date researchTime;

    public DeDemandResearch buildResearch() {
        DeDemandResearch research = new DeDemandResearch();
        BeanUtils.copyProperties(this,research);
        if(!CollectionUtils.isEmpty(getResearchSystem())){
            research.setResearchSystem(getResearchSystem().stream().collect(Collectors.joining(",")));
        }
        if(!CollectionUtils.isEmpty(getResearchUser())){
            research.setResearchUser(getResearchUser().stream().map(data->data.toString()).collect(Collectors.joining(",")));
        }
        research.setResearchEnclosure(FileUtils.fileToId(getResearchEnclosure()));
        research.setCreateUser(SecurityUtils.getUserId());
        research.setCreateTime(DateUtils.getNowDate());
        return research;
    }
}
